<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 * $Id: 2017-12-13 03:39:35 apple $
*/
//客服设置
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'base';
$return=array();
$return['autotypes']=array('0'=>'客服组内共享','1'=>'全部客服共享');
if($_RQ['op']=='base'){
	$return['item']=pdo_get('jy_kefu_set',array('uniacid'=>$_SESSION['uniacid']));
	$return['item']['url']=custom_url('jy_kefu/home/',true);
	$return['item']['hdp']=$return['item']['hdp']?json_decode($return['item']['hdp'],true):array();
	$htmls=array(
			'type'=>'edit',
			'post'=>'basepost',
			'desc'=>'基本信息',
			'edit_tab'=>true,
			'tabs'=>array(
				'0'=>array('op'=>'base','title'=>'客服设置'),
			),
			'edits'=>array(
				array(
					'title'=>'基础设置',
					'list'=>array(
						array('type'=>'tip','title'=>'<red>公众号的消息提醒，是有时间间隔的，一般间隔5分钟，后台可以自由设置间隔时间；不是客户每次有消息就提醒的，不然很容易被封了</red>'),
						array('type'=>'ewm','title'=>'客服中心二维码','name'=>'url', 'help'=>'' ),
						array('type'=>'copy','title'=>'客服中心链接','name'=>'url', 'help'=>'' ),
						array('type'=>'string','title'=>'客服中心标题','name'=>'title', 'help'=>'' ),
						array('type'=>'text','title'=>'敏感词过滤','name'=>'filterword', 'help'=>'多个敏感词可用|隔开' ),
						array('type'=>'switch','title'=>'开启共享聊天记录','name'=>'isautomsg', 'help'=>'' ),
						array('type'=>'radio','title'=>'聊天记录共享类型','name'=>'autotype', 'options'=>'autotypes','show'=>array('isautomsg'=>1)),
						array('type'=>'string','title'=>'聊天界面背景颜色','name'=>'bgcolor', 'help'=>''),
						array('type'=>'string','title'=>'界面主色调','name'=>'confcolor', 'help'=>'' ),
					)
				),
				array(
					'title'=>'消息提醒设置',
					'list'=>array(
						//array('type'=>'switch','title'=>'开启消息提醒','name'=>'isremind', 'help'=>'' ),
						array('type'=>'tip','title'=>'48小时内要给公众号发过关键字（48小时内未交互，可能收不到客服消息！）', 'help'=>''),
						array('type'=>'unitstring','title'=>'消息提醒时间间隔','name'=>'kefuremindtime', 'unit'=>'秒', 'help'=>'防止<em>频繁消息</em>提醒，要设置时间间隔。默认120秒，间隔提醒'),
					)
				),
				array(
					'title'=>'幻灯片',
					'list'=>array(
								array(
									'type'=>'array',
									'name'=>'hdp',
									'add_tip'=>'添加一个幻灯片',
										'list'=>array(
											array('type'=>'image','name'=>'picurl','title'=>'幻灯片图片'),
											array('type'=>'string','name'=>'url','title'=>'幻灯片链接'),
											
										),
										'details'=>array(
											array('type'=>'image','name'=>'picurl','title'=>'幻灯片图片','help'=>''),
											array('type'=>'string','name'=>'url','title'=>'幻灯片链接'),
											
										)
								),
						)
				),
				array(
					'title'=>'关注设置',
					'list'=>array(
						array('type'=>'string','title'=>'分享标题','name'=>'sharetitle', 'help'=>''),
						array('type'=>'image','title'=>'分享图片','name'=>'sharepicurl', 'help'=>''),
						array('type'=>'text','title'=>'分享描述','name'=>'sharedes', 'help'=>''),
						array('type'=>'image','title'=>'未关注用户头像','name'=>'nologo', 'help'=>''),
						array('type'=>'switch','title'=>'是否开启关注提醒','name'=>'isunfollow','help'=>'开启后，将弹出关注二维码（调用站点设置里面的二维码）'),
					)
				),
				/*array(
					'title'=>'机器人设置',
					'list'=>array(
						array('type'=>'string','title'=>'机器人的KEY','name'=>'jyrobotkey', 'help'=>'如果没有申请KEY，请留空！！你也可以去系统申请自己独立的KEY：http://ai.jinyunweb.com/' ),
						array('type'=>'switch','title'=>'是否开启机器人','name'=>'isjyrobot','help'=>''),
					)
				),*/
			)
	);
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='basepost'){
	$postdata=get_postdata();
	if($_SESSION['user']['type']<3 && !$_SESSION['isfounder']){
		exi('您没有权限设置！','error');
	}
	if($postdata['kefuremindtime']<100){
		exi('消息间隔时间不能小于100秒！','error');
	}
	$data=array(
		'title'=>trim($postdata['title']),
		'isremind'=>trim($postdata['isremind']),
		'sharetitle'=>trim($postdata['sharetitle']),
		'sharedes'=>trim($postdata['sharedes']),
		'sharepicurl'=>trim($postdata['sharepicurl']),
		'kefuremindtime'=>trim($postdata['kefuremindtime']),
		'tpl_kefu'=>trim($postdata['tpl_kefu']),
		'bgcolor'=>trim($postdata['bgcolor']),
		'nologo'=>trim($postdata['nologo']),
		'isautomsg'=>trim($postdata['isautomsg']),
		'autotype'=>trim($postdata['autotype']),
		'isunfollow'=>trim($postdata['isunfollow']),
		'filterword'=>trim($postdata['filterword']),
		'confcolor'=>trim($postdata['confcolor']),
		'groupremind'=>trim($postdata['groupremind']),
		'groupremindtime'=>trim($postdata['groupremindtime']),
		'groupshowindex'=>trim($postdata['groupshowindex']),
		'showgroupnum'=>trim($postdata['showgroupnum']),
		'jyrobotkey'=>trim($postdata['jyrobotkey']),
		'isjyrobot'=>trim($postdata['isjyrobot']),
		'hdp'=>ijson_encode($postdata['hdp']),
	);
	$check=pdo_getcolumn('jy_kefu_set',array('uniacid'=>$_SESSION['uniacid']),'id');
	if($check){
		pdo_update('jy_kefu_set',$data,array('uniacid'=>$_SESSION['uniacid']));
	}else{
		$data['uniacid']=$_SESSION['uniacid'];
		pdo_insert('jy_kefu_set',$data);
	}
	
	exi('设置成功！');
}
?>